/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package hcmus.fit.master.sevensea.control;

import hcmus.fit.master.sevensea.R;
import hcmus.fit.master.sevensea.core.Constant;
import hcmus.fit.master.sevensea.util.Size;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;

/**
 * 
 * @author hvp
 */
public class Control {
    // public
    private Size _size;

    // public static Image BackGround;
    public Score _Score;
    public Level _Level;
    public Life _Life;
    private int _bonusLife;
    private static Bitmap BackGround;

    public static void LoadResources(Resources resources) {
        try {
            Bitmap img = BitmapFactory.decodeResource(resources, R.drawable.scorenumber);
            Level.Resources = Life.Resources = Score.Resources = Score
                    .GetResource(img, 10, 1, 1, 1);

            img = BitmapFactory.decodeResource(resources, R.drawable.lifeicon);
            Life.Icon = Bitmap.createBitmap(img, 0, 0, img.getWidth(), img.getHeight());

            img = BitmapFactory.decodeResource(resources, R.drawable.sliderthumb);
            Level.Icon = Bitmap.createBitmap(img, 0, 0, img.getWidth(), img.getHeight());
            BackGround = BitmapFactory.decodeResource(resources, R.drawable.control);
        } catch (Exception ex) {
        }
    }

    public Control(Size size) {
        _size = size;

        _Score = new Score(0);
        _Level = new Level(1);
        _Life = new Life(4);
        _bonusLife = 0;
    }

    public void Show(Canvas g) {
        if (_Score.SCORE / 1000 != _bonusLife) {
            _Life.LIFE++;
            _bonusLife++;
        }
        _Level.Show(g, 50, 8);
        _Life.Show(g, 225, 8);
        Bitmap tmp = Bitmap.createBitmap(BackGround.getWidth(), BackGround.getHeight(),
                Constant.BITMAP_CONFIG);
        Canvas g1 = new Canvas(tmp);
        g1.drawBitmap(BackGround, 0, 0, new Paint());
        _Score.Show(g1, 120, 38);
        g.drawBitmap(tmp, new Rect(0, 0, tmp.getWidth(), tmp.getHeight()), new Rect(0, _size.Height
                - tmp.getHeight(), tmp.getWidth(), _size.Height), new Paint());
    }

}
